A r t i c l e s
Navigation

Note: This site is
a bit older, personal views
may have changed.

M a i n P a g e

D i r e c t o r y

What Is CGI



Please take it with some pinch of salt.. 


CGI has caused some confusion. Many users assume CGI is some form of perl or scripting system. There are many cgi scripts out there that happen to be perl. But scripts are not what CGI was meant for. CGI, at it's best, is for programs. With a compiler like FreePascal or a C++ compiler, or a C compiler, you can have powerful CGI programs available which can do far more than a PHP script can.
PHP cs CGI vs Perl... People say CGI is SLOW! CGI is not scalable! PHP calls on the interpretter, a large one, which is a huge process that the server has to fork open. With a cgi program, medium sized websites will have applications sometimes only 50-200KB in size (that's a fairly big command line program that can do a lot of things) whereas the PHP interpretter will have to call on about 12MB of libraries, at least.. in order to run any small PHP script. The same goes with perl... Perl CGI scripts or MOD_Perl scripts call on the interpretter, a large one, which is a huge process that the server has to fork open. Most websites, however, are such small ones that speed and size isn't really an issue. Perl scripts and PHP scripts, whether CGI or not, still have to call the interpreter. A freepascal or C++ CGI program is standalone and does not call on any large 12MB interpretter, hence this puts those rumors dead that CGI is slow. If you want to see a benchmark on CGI, and why rumors are wrong, see here: ASP vs PHP vs CGI benchmark
Since there are many perl CGI scripts floating about, people assume that CGI is perl. CGI is just a simple way of stating that you can create a website with a program. Common Gateway Interface. A gateway for your programs to be able to talk to a web browser. On GnuLinux, any ELF executable can be a website. On Windows, any EXE file can be a website. The file can output via the standard I/O procedures.. i.e. in Pascal: WriteLn('Write some text'); The CGI program runs on the server in the CGI-BIN directory. The CGI program must have executable rights. On linux, usually this isn't a problem. You just change the attributs of the ELF file you uploaded to the CGI-BIN directory. On windows, some hosts will have to do some permissions settings for CGI-BIN to work, or they may not even know what a CGI-BIN directory is really for (a lot of the losers think CGI is just for perl or python).
CGI rumors: CGI is not scalable? Yes it is. Move to a bigger server and your php.INI file might not work any more. With CGI, you create your own INI files if you want to. Ebay, paypal, Borland uses cgi. use CGI. Lots of big companies use perl or php or java, or CGI. None are superior to the other (in my situation, due to code re-use, pascal cgi is superior for myself) Many companies use CGI but you just don't know it. The extension doesn't have to end in CGI in order to be CGI. These are all big companies. Don't kid me with "it's not scalable". There are also ways to launch persistent 'helper' processes which allow you to talk to a exe/elf that runs all the time (and there is also fastcgi) so that the processes are not continually launched over and over again for certain common tasks. However, this is premature optimization and most operating systems cache things behind your back which makes performance excellent already, or operating systems share the code segment between multiple executables. I have to compile when using a CGI program, and this sucks Your customer has to wait for the interpretter and 12MB of other stuff when using php, so? You decide. Is it the customer who is waiting or the developer? Customers Come First You can debug your program offline or debug it online. You decide. A crashing php forum might have been saved if you would have debugged it offline with compiler checking the basic things. Humans do make simple mistakes, which can be caught before deploying. True, you can check a PHP script to locally before uploading it live - but compilers still have advantages such as checking for horrible errors that many programmers still make, even experienced ones. True, you can write unit tests to check your scripts, but some unit tests are tedious tests that sometimes a compiler can do for you. One can still write unit tests with a compiled program too - so isn't using a compiler, plus unit tests, a form of double-testing? Which would be safer than just running unit tests alone. Uploading a program is inconvenient and larger than a script. Having someone hack into your server and see all your source files and passwords in your script is even more inconvenient.


About
This site is about programming and other things.
_ _ _